/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package scrabble;

import java.awt.*; 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
/**
 *
 * @author OTHMAN
 */
public class Choix  extends JFrame{
    
    private  ButtonGroup gb= new ButtonGroup();
    private  JRadioButton r1 = new JRadioButton("1 joueur"); 
    private  JRadioButton r2 = new JRadioButton("2 joueurs");
    public int ch;
    public static Jeu j;
    JButton entree = new JButton("Entrez"); 
     JPanel fen;
    private  MonListener l= new MonListener();
    private String nom1="";
    private String nom2="";
    
    public int resultat()
    {
        if(r1.isSelected())
        return 1;
        if(r2.isSelected())
        return 2;
        return 0;
    }
  
             


  public Choix() { 
      this.setTitle("Choix");
     
    this.setBounds(600,300,250,150); 
    this.setLayout(new FlowLayout( )); 
    r1.setBounds(20, 25, 88, 23);  
    r2.setBounds(20, 55, 108, 23);
    r1.setSelected(true);
    gb.add(r1);
    gb.add(r2);
    this.add(entree); 
    this.add(r1); 
    this.add(r2); 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.show( );
    entree.addActionListener(l);
    this.setResizable(false);
    
   } 
  public class MonListener implements ActionListener {
	public void actionPerformed(ActionEvent e) { 
            if(resultat()==1)
            {
                do
                {
                nom1 = JOptionPane.showInputDialog(null, "Quel est votre nom?",
                "Entrez votre nom",  JOptionPane.QUESTION_MESSAGE);
                }
                while("".equals(nom1));
                
                j=new Jeu(1,nom1,"");
               
           dispose(); 
            }
  if(resultat()==2)
  {
      do
      {
      nom1 = JOptionPane.showInputDialog(null, "Le nom du premier joueur",
                "entrez le nom du premier joueur",  JOptionPane.QUESTION_MESSAGE);
      }
                while("".equals(nom1));
      do
      {
        nom2 = JOptionPane.showInputDialog(null, "Le nom du premier joueur",
                "entrez le nom du premier joueur",  JOptionPane.QUESTION_MESSAGE);
        }
                while("".equals(nom2));
        ch=2;
        j=new Jeu(2,nom1,nom2);
    dispose(); 
  }
  if(resultat()==0)
  {
        ch=3;
        System.exit(0);
  }
  
  }
	 
} 
}